clear all

use Master2018.dta

// gen post_1985 = 0
// replace post_1985 = 1 if date >=31124 //Tenth schedule came into effect on 18th March 1985

gen post_1985 = 0
replace post_1985 = 1 if date >=31776 //Wadhwa decision 20th Dec 1986

replace both_overall = both_overall[_n-1] if missing(both_overall)

egen firstdate_break = min(date) if bothinbreak == 1, by(both_overall)
label var firstdate "Date of start of Break"

egen lastdate_break = max(date) if bothinbreak == 1 , by(both_overall)
label var lastdate "Date of end of Break"

// egen firstdate_session = min(date) if bothinsession == 1 , by(both_overall)
// replace firstdate_session = l.firstdate_session if firstdate_session >= .
// label var firstdate_session "Date of start of Session"

// egen lastdate_session = max(date) if bothinsession ==1 , by(both_overall)
// replace lastdate_session = l.lastdate_session if lastdate_session >=.
// label var lastdate_session "Date of end of Session"

// gen session_length = lastdate_session - firstdate_session
// label var session_length "Total days of overall session"

// gen break_length = lastdate_break - firstdate_break
// label var break_length "Total days of break"


gen day_break = date - firstdate_break
label var day_break "Number of days from start of break"
gen prop_day_break = day_break / (lastdate_break - firstdate_break)
label var prop_day_break "Proportion of time to the end of the break"

drop if bothinsession == 1
sort prop_day_break




// gen cume_maj = sum(ordinances) / 386 if LSmaj == 1
// gen cume_min = sum(ordinances) / 305 if LSmaj == 0

// //There are 309 ords with LegisMaj govts and 382 with minority
// label var cume_maj "LS Majority governments"
// label var cume_min "LS Minority governments"

// twoway line cume_maj cume_min prop_day_break, scheme(s2mono)

//There are 310 ords with SPMaj, 123 with SPMin, 86 with MajPC, and 172 with MinC

// gen cume_spmaj = sum(ordinances) / 310 if govt_type == 0
// gen cume_spmin = sum(ordinances) / 123 if govt_type == 1
// gen cume_majpc = sum(ordinances) / 86  if govt_type == 2
// gen cume_minc  = sum(ordinances) / 172 if govt_type == 3

// label var cume_spmaj  "Single Party Majority"
// label var cume_spmin  "Single Party Minority"
// label var cume_majpc  "Majority Party Coalition"
// label var cume_minc   "Minority Coalition"

// twoway(line cume_spmaj cume_spmin cume_majpc cume_minc prop_day_break)

//The numbers 261, 53, 33, 344 below are based on 18th March 1985 cut off
// gen cume_maj_pre = sum(ordinances) / 261 if post_1985 == 0 & LegisMaj == 1
// gen cume_min_pre = sum(ordinances) / 53  if post_1985 == 0 & LegisMaj == 0 
// gen cume_maj_pst = sum(ordinances) / 33  if post_1985 == 1 & LegisMaj == 1 
// gen cume_min_pst = sum(ordinances) / 344 if post_1985 == 1 & LegisMaj == 0 

//The number 274, 53, 20, 344 below are based on 20th Dec 1986 cut off
// gen cume_maj_pre = sum(ordinances) / 274 if post_1985 == 0 & LegisMaj == 1
// gen cume_min_pre = sum(ordinances) / 53  if post_1985 == 0 & LegisMaj == 0 
// gen cume_maj_pst = sum(ordinances) / 20  if post_1985 == 1 & LegisMaj == 1 
// gen cume_min_pst = sum(ordinances) / 344 if post_1985 == 1 & LegisMaj == 0 

// label var cume_maj_pre  "Bicameral maj pre  1986"
// label var cume_min_pre  "Bicameral min pre  1986"
// label var cume_maj_pst  "Bicameral maj post 1986"
// label var cume_min_pst  "Bicameral min post 1986"

//Bicameral maj 294, Min in both 296, only RS min 92, only LS min 9
gen cume_maj_both   = sum(ordinances) / 294 if bicam_type == 0
gen cume_min_both   = sum(ordinances) / 305 if bicam_type == 1 
gen cume_min_onlyRS = sum(ordinances) / 92  if bicam_type == 2 

label var cume_maj_both  "Bicameral Majority"
label var cume_min_both  "Minority in Both"
label var cume_min_onlyRS  "Only Minority in RS"

//twoway line cume_maj_pre cume_min_pre prop_day_break, scheme(s2mono)

//twoway line cume_maj_pst cume_min_pst prop_day_break, scheme(s2mono)

twoway line cume_maj_both cume_min_both cume_min_onlyRS prop_day_break, scheme(s2mono)
